﻿package com.tudou.home.controller
{
    import com.tudou.home.commands.*;
    import com.tudou.home.commands.ad.*;
    import com.tudou.home.model.*;
    import com.tudou.v2.*;
    import org.puremvc.as3.interfaces.*;
    import org.puremvc.as3.patterns.command.*;

    public class V2Command extends SimpleCommand
    {

        public function V2Command()
        {
            return;
        }// end function

        private function v2Passed(param1:VideoInfo) : void
        {
            var _loc_2:* = StatusInfo.getInst();
            _loc_2.v2 = StatusInfo.V2_PASSED;
            if (_loc_2.ad == StatusInfo.AD_INIT)
            {
                sendNotification(AdCommandSet.ADINFO_START_LOAD);
            }
            var _loc_3:* = facade.retrieveProxy(PlayerProxy.NAME) as PlayerProxy;
            _loc_3.videoInfo = param1;
            var _loc_4:* = facade.retrieveProxy(PageProxy.NAME) as PageProxy;
            (facade.retrieveProxy(PageProxy.NAME) as PageProxy).setAllRateTypeURLs(param1.getRateTypeURLs());
            sendNotification(PrivacyCommandSet.RIGHT_PASSWORD);
            return;
        }// end function

        override public function execute(param1:INotification) : void
        {
            var _loc_4:VideoInfo = null;
            var _loc_2:* = facade.retrieveProxy(V2Proxy.NAME) as V2Proxy;
            var _loc_3:* = PageInfo.getInstance();
            switch(param1.getName())
            {
                case V2CommandSet.START_LOAD:
                {
                    _loc_2.load(_loc_3, _loc_3.password);
                    StatusInfo.getInst().v2 = StatusInfo.V2_REQUESTING;
                    break;
                }
                case V2CommandSet.INFO_LOADED:
                {
                    _loc_4 = param1.getBody() as VideoInfo;
                    _loc_3.videoTotalTime = _loc_4.videoTotalTime;
                    v2Passed(_loc_4);
                    break;
                }
                case V2CommandSet.INFO_ERROR:
                {
                    v2Unpassed(int(param1.getBody()));
                    break;
                }
                default:
                {
                    break;
                    break;
                }
            }
            return;
        }// end function

        private function v2Unpassed(param1:int) : void
        {
            var _loc_2:* = StatusInfo.getInst();
            if (param1 == 9)
            {
                _loc_2.v2 = StatusInfo.V2_UNPASSED;
                if (_loc_2.ad == StatusInfo.AD_INIT || _loc_2.ad == StatusInfo.AD_FRONT_SHOWED)
                {
                    sendNotification(PrivacyCommandSet.WRONG_PASSWORD);
                }
                else
                {
                    return;
                }
            }
            else
            {
                sendNotification(PrivacyCommandSet.HIDE_PRIVACY_PANEL);
            }
            return;
        }// end function

    }
}
